When I want to sort an array of elements there are a number of programming techniques I can use. I quite like the "Bubble Sort". This involves looking at adjacent pairs of number in the array and swapping them around if they are in the wrong order. If you work your way through the array a few times doing this you find that all the large numbers "bubble" to the top and the small ones sink to the bottom. All this is performed under the control of for loops.
This means that we can easily create a little program which will sort an array of any size into ascending order. It is interesting to note that a sort program like this does not work in the same way that a human would do the job, but then again if you sort 100 numbers you'd probably not know how it was you did it in the first place!
Bubble Sort
-
Start at the beginning of the array
-
Compare the first and second items. If they are in the wrong order, swap them.
-
Now compare the second and third items.
-
Go on until you reach the end of the array
-
Go back to the top and do it again.
-
Repeat until you make a pass through the array and don't do any swaps.